package com.exception.controller;

import com.exception.exception.MyException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/exception")
public class ExceptionController {
    @GetMapping("/test/{name}")
    public void testException(@PathVariable String name) {
        if (name == null || "zhp".equalsIgnoreCase(name)) {
            throw new MyException(HttpStatus.NOT_ACCEPTABLE, 1001, "name error!", null);
        } else {
            throw new RuntimeException("runtime exception");
        }
    }
}
